/*
 */
package it.pride.primefacesShowcase.filters;

import java.util.Date;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author eluibon
 */
public class DateInterval extends EmptyFilter implements Filter {

    private Date startDate;
    private Date endDate;

    public DateInterval(String property, Date startDate, Date endDate) {
        super(property) ;        
        this.startDate = startDate;
        this.endDate = endDate;
    }

    @Override
    public Criterion getCriterion() {

        if ((startDate == null) && (endDate == null)) {
            return null;
        }

        if (endDate == null) {
            return Restrictions.ge(property, startDate);
        }

        if (startDate == null) {
            return Restrictions.le(property, endDate);
        }

        return Restrictions.between(property, startDate, endDate);
    }

    @Override
    public String toString() {
        return "DateInterval{" + "startDate=" + startDate + ", endDate=" + endDate + '}';
    }
    
}
